from flask import Blueprint, render_template
from models import House
# 创建蓝图，蓝图的名称为包的名称index_page
index_page = Blueprint('index_page', __name__)

# @index_page.route('/')
# def index():
#     house_total_num = House.query.count()  # 获取房源总数量
#     return render_template('index.html', num=house_total_num)

# @index_page.route('/')
# def index():
#     house_total_num = House.query.count()  # 获取房源总数量
#     # 获取最新房源TOP6
#     house_new_list = House.query.order_by(
#                               House.publish_time.desc()).limit(6).all()
#     return render_template('index.html', num=house_total_num,house_new_list=house_new_list)

@index_page.route('/')
def index():
    house_total_num = House.query.count()# 获取房源总数量
    # 获取最新房源TOP6
    house_new_list = House.query.order_by(
	 House.publish_time.desc()).limit(6).all()
    # 获取最热房源TOP4
    house_hot_list = House.query.order_by(House.page_views.desc()).limit(4).all()
    return render_template('index.html', num=house_total_num,house_new_list=house_new_list,house_hot_list=house_hot_list)
